function [fh] = conbarplot(u, rng, varname, groupnames, plotsum)
    %--plot the bar chart
    
    if nargin<5
        plotsum=1;
    end
    
 %   if istseries(u)
%         u=resize(u, rng);
%         u=u.data;
%     else
        u=u(rng,:);
%     end
    
    
    
    %-split
    upos=zeros(size(u));
    upos(find(u>0)) = u(find(u>0));
    uneg=zeros(size(u));
    uneg(find(u<0)) = u(find(u<0));
    %-tserize
    tspos = tseries(rng,upos);
    tsneg = tseries(rng,uneg);

    %-set colormap
%     cmp = hsv(length(groupnames));
%     colormap(cmp);

%     fh = figure('visible','on');
    bar(tspos,'stacked');hold on;
    bar(tsneg,'stacked');hold on;

%     %-plot sum
%     if plotsum
%         cmsm = sum(tspos+tsneg,2);
%         pp = plot(rng,cmsm,'linewidth',2);
%     end

    %-put legend
%     ll = legend(groupnames,'location','SouthOutside','orientation','horizontal');
%    ll = legend(groupnames,'location','NorthWest','orientation','vertical');

    %-title
    title(varname,'interpreter','none');
    hold off;
end